<?php
use yii\helpers\Url;
use app\common\widgets\Page;
use yii\widgets\LinkPager;
?>

<section class="vbox">

    <section class="scrollable padder">

        <div class="m-b-md">
            <h3 class="m-b-none"></h3>
        </div>



        <section class="panel panel-default">
            <header class="panel-heading">
                用户列表
            </header>
            <div class="row wrapper">
                <div class="col-sm-5 m-b-xs">
                    <a href="<?php echo \Yii::$app->urlManager->createUrl("user/add"); ?>" class="btn btn-sm btn-default"><i class="fa fa-plus"></i>添加</a>
                </div>
                <div class="col-sm-4 m-b-xs">

                </div>
                <form action="<?php echo \Yii::$app->urlManager->createUrl("user/lists"); ?>" method="get" class="form-horizontal">
                    <div class="col-sm-3">
                        <div class="input-group">
                            <input type="text" class="input-sm form-control" placeholder="请输入名称" name="keyword" value="<?php echo $filter['keyword'];?>">
                          <span class="input-group-btn">
                            <button class="btn btn-sm btn-default" type="submit">搜索</button>
                          </span>
                        </div>
                    </div>
                </form>
            </div>
            <div class="table-responsive">
                <table class="table table-striped b-t b-light">
                    <thead>
                    <tr>
                        <th style="width:20px;"><label class="checkbox m-n i-checks"><input type="checkbox"><i></i></label></th>
                        <th>编号</th>
                        <th>用户名</th>
                        <th>权限</th>
                        <th>姓名</th>
                        <th>登录次数</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach((array)$data as $key=>$info):?>
                        <tr id="list_<?php echo $info['id'];?>">
                            <td><label class="checkbox m-n i-checks"><input type="checkbox" name="check"  value="<?php echo $info['id'];?>"><i></i></label></td>
                            <td><?php echo $info['id'];?></td>
                            <td>
                                <?php echo $info['username'];?>
                            </td>
                            <td>
                                <?php echo $info['role']['name'];?>
                            </td>
                            <td>
                                <?php echo $info['nick'];?>
                            </td>

                            <td><?php echo $info['countlog'];?></td>
                            <td>
                                <?php if($info['status'] == 1){?>
                                    <span class="label bg-success">启用</span>
                                <?php }else {?>
                                    <span class="label bg-danger">停用</span>
                                <?php }?>
                            </td>
                            <td>
                                <a href="<?php echo Url::toRoute(['user/edit', 'id' => $info['id']]);?>" >
                                    <i class="fa  fa-edit"></i>
                                </a>
                                <a href="javascript:void(0);" data-toggle="tooltip" class="del_checked" href="javascript:void(0);" title="删除"  data-original-title="删除" data-id="<?php echo $info['id'];?>" data-title="<?php echo $info['username'];?>">
                                    <i class="fa fa-trash-o text-muted"></i>
                                </a>


                            </td>
                        </tr>
                    <?php endforeach?>

                    </tbody>
                </table>
            </div>

        </section>
    </section>
    <footer class="footer bg-white b-t" data-type="ajaxPage">
        <div class="row text-center-xs">
            <div class="col-md-6 hidden-sm">
                <p class="text-muted m-t">总共<?php echo $total;?>条 当前为第<?php echo $filter['page'];?>页</p>
            </div>
            <div class="col-md-6 col-sm-12 text-right text-center-xs">
<!--                				--><?//= LinkPager::widget(['pagination' => $pages]); ?>
                <?php if($total > 0):echo Page::model(array('count'=>$total,'size'=>$limit))->show("NewPage");endif;?>
            </div>
        </div>
    </footer>
</section>

<script>
    $(document).ready(function() {

        var $del_checked = $("a.del_checked");
        $del_checked.click(function () {
            var id = $(this).data("id");
            var name = $(this).data('title');
            bootbox.dialog({
                message: '<p>确定删除标签 <font style="color:red">'+name+'</font> ?',
                title: "确定删除此记录?",
                buttons: {
                    danger: {
                        label: "确定",
                        className: "btn btn-success",
                        callback: function() {
                            $.ajax({
                                url:"<?php echo \Yii::$app->urlManager->createUrl("user/dodel"); ?>",
                                cache:false,
                                type:'POST',
                                dataType:'json',
                                data:{"id":id},
                                success:function(msgObj){
                                    if(msgObj.status == '0'){
                                        $("#list_"+id).remove();
                                        G.ui.tips.suc(msgObj.message);
                                        return false;
                                    }else{
                                        G.ui.tips.err(msgObj.message);
                                        return false;
                                    }
                                }
                            });
                        }
                    },
                    main: {
                        label: "取消",
                        className: "btn btn-default",
                        callback: function() {}
                    }
                }
            });
        });
    });

    function deleteAll(){
        var ids = '';
        $('input[name=check]').each(function(){
            if($(this).is(':checked')) {
//            if ($(this).attr("checked")) {
                ids += ","+$(this).val();
            }
        });
        if(ids == '') {
            G.ui.tips.err("请选择需要删除的数据");return false;
        }
        bootbox.setDefaults("locale","zh_CN");

        bootbox.confirm("确定要删除选中的吗 ?" , function(result) {
            if(result) {
                $.ajax({
                    url:"<?php echo \Yii::$app->urlManager->createUrl("tag/doalldel"); ?>",
                    cache:false,
                    type:'POST',
                    dataType:'json',
                    data:{"ids":ids},
                    success:function(msgObj){
                        if(msgObj.code == '0'){
                            G.ui.tips.suc(msgObj.msg);
                            return false;
                        }else{
                            G.ui.tips.err(msgObj.msg);
                            return false;
                        }
                    }
                });
            } else {
                return false;
            }
        });
    }

    function Taghit(id,status) {
        var url = "<?php echo \Yii::$app->urlManager->createUrl("tag/dohit"); ?>";
        var str_msg = status == 0 ? "取消置顶" : "置顶";
        bootbox.setDefaults("locale","zh_CN");

        bootbox.confirm("确定要"+str_msg+"该记录吗 ?" , function(result) {
            if(result) {
                $.post(url,{id:id,status:status},function(msgObj){
                    if(msgObj.code == '0') {
                        G.ui.tips.suc(msgObj.msg);
                        return false;
                    }else{
                        G.ui.tips.err(msgObj.msg);
                        return false;
                    }
                },'json');
            } else {
                return false;
            }
        });

    }
</script>
